<template>
  <div>
    <NavBar @submit="submit"></NavBar>
    <br>
    <el-card>
      <el-row>
        <el-col :span="24">
          <div class="图表1">
            <ECharts :options="config"></ECharts>
          </div>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script setup>
import NavBar from './components/NavBar.vue'
import ECharts from '@/components/Echarts/Index.vue'
import { options } from './data.js'
import { getOptions2 } from '@/api/Benefit.js'
import { ref } from "vue";
import { dayjs } from 'element-plus'
import { ElMessage } from "element-plus";

const from = ref({
  year: new Date().getFullYear(),
})

const config = ref(options)

const search = async () => {
  const res = await getOptions2(from.value)
  if (!res.data.length) ElMessage.warning('暂无数据')
  config.value.xAxis.data = res.data.map(_ => dayjs(_._id).format('M'))
  config.value.series[0].data = res.data.map(_ => _.total)
}
search()
const submit = async (data) => {
  from.value = JSON.parse(JSON.stringify(data))
  from.value.year = new Date(data.year).getFullYear()
  from.value.项目院内代码 = from.value.收费代码
  delete from.value.收费代码
  console.log(from.value)
  await search()
}
</script>

<style scoped>
.图表1 {
  height: 600px;
}
</style>